class Solution:
    def islandPerimeter(self, grid):
        """
        :type grid: List[List[int]]
        :rtype: int
        """
        l_column = len(grid[0])
        l_row = len(grid)
        grid.insert(0, [0] * l_column)
        grid.append([0] * l_column)

        for row in grid:
            row.insert(0, 0)
            row.append(0)

        sum = 0
        for i in range(1, l_row + 1):
            for j in range(1, l_column + 1):
                if grid[i][j] == 1:
                    a = grid[i - 1][j] == 1
                    b = grid[i + 1][j] == 1
                    c = grid[i][j - 1] == 1
                    d = grid[i][j + 1] == 1
                    sum += 4 - (a + b + c + d)
        return sum

s = Solution()
print(s.islandPerimeter([[1,0,0]]))
print(s.islandPerimeter([[0, 1, 0, 0],
                         [1, 1, 1, 0],
                         [0, 1, 0, 0],
                         [1, 1, 0, 0]]))
